home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ww_tv.exe
/
TVEDIT4.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-03
|
6KB
|
171 lines
/****************************************************************************/
/* */
/* Copyright (c) 1991 Primatech Inc. */
/* */
/* All Rights Reserved */
/* */
/****************************************************************************/
// $config$=/MTVEdit4.cpp
//
// $NAME$:
// ..Module Overview
//
// $GLOBAL PATHS$
// modules\all\TVEdit4.cpp
// modules\c++\TVEdit4.cpp
// objects\TEditorApp
//
// $0$
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Purpose: To implement a macro recording a playback facility. This is
// useful for testing and profiling the editor code.
//
// Prototypes location: $/SEE(.hpp)$
//
// Other Information:
//
// See also: $/SEE()$
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//$-1$
#if 0
//$1$
/**** MODIFICATIONS HISTORY ****/
Created: 13 November 1991 by John L. Swartzentruber
$SKIP START$
#endif
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+ +*/
/*+ I N C L U D E F I L E S +*/
/*+ +*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <stdio.h>
#include <dos.h>
#define Uses_TApplication
#define Uses_TEvent
#define Uses_TStatusLine
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TKeys;
#include <tv.h>
#include "TVEdit.h"
//$SKIP END$
//$2$
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+ +*/
/*+ # D E F I N E S C L A S S E S and T Y P E D E F S +*/
/*+ +*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//$3$
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+ +*/
/*+ E X T E R N A L D E F I N I T I O N S +*/
/*+ +*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//$4$
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+ +*/
/*+ S T A T I C D E F I N I T I O N S +*/
/*+ +*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//$END$
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*+ +*/
/*+ S T A T I C F U N C T I O N P R O T O T Y P E S +*/
/*+ +*/
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* EJECT */
//****************************************************************************
//
// Function $NAME$:
// TEditorApp::getEvent(TEvent&)
// $1$
//
// Purpose: To get an event. If recording, save the event in a
// file. If playing back, read the event from the file.
// If neither of the above, act like normal.
//
// Return: None
//
// Other information:
//
// This is just a quick and dirty hack.
//
//$0$
//****************************************************************************
void TEditorApp::getEvent(TEvent& event)
// $END$
{
static FILE* macro_file = 0;
static enum MacroState {Nothing, Playing, Recording} state = Nothing;
if (state == Playing && macro_file != 0) {
if (fread(&event, sizeof(event), 1, macro_file) != 1) {
fclose(macro_file);
macro_file = 0;
state = Nothing;
} else {
putEvent(event);
}
clearEvent(event);
}
TApplication::getEvent(event);
if (state == Recording && event.what != evNothing && macro_file != 0) {
// Don't write the record key that ends the recording.
if (event.what != evCommand || event.message.command != cmRecord) {
fwrite(&event, sizeof(event), 1, macro_file);
}
}
switch (event.what) {
case evCommand:
if (macro_file == 0 && event.message.command == cmPlay) {
clearEvent(event);
macro_file = fopen("KeyFile.dat", "rb");
state = Playing;
// The record key is a toggle
} else if (event.message.command == cmRecord) {
clearEvent(event);
if (macro_file == 0) {
macro_file = fopen("KeyFile.dat", "wb");
state = Recording;
} else {
fclose(macro_file);
macro_file = 0;
state = Nothing;
}
}
break;
}
}